package cn.yh.dao;

import cn.yh.model.User;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

@Component
public class UserDaoImpl implements UserDao{

    @Override
    public User findById(int id) {
        ApplicationContext app = new ClassPathXmlApplicationContext("applicationContext.xml");
        JdbcTemplate bean = app.getBean(JdbcTemplate.class);
        String sql = "select * from user where id = ?";
        return bean.queryForObject(sql,User.class,id);
    }
}
